package com.egao.orderB.service.impl;

import com.egao.common.core.utils.Utils;
import com.egao.common.core.web.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
//import com.egao.orderB.mapper.BillFeeMapper;
import com.egao.orderB.entity.BillFee;
import com.egao.orderB.service.BillFeeService;
import org.springframework.stereotype.Service;
import com.egao.orderB.biz.BillFeeBiz;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 订单运费服务实现类
 * @author : Doman
 * @date : 2020-06-15 16:11:54
 * @version ：1.0
 */
@Service
public class BillFeeServiceImpl /*extends ServiceImpl<BillFeeMapper, BillFee> */implements BillFeeService {

	@Autowired
	private BillFeeBiz billFeeBiz;

    /**
    @Override
    public PageResult<BillFee> listPage(PageParam<BillFee> page) {
        List<BillFee> records = baseMapper.listPage(page);
        return new PageResult<>(records, page.getTotal());
    }

    @Override
    public List<BillFee> listAll(Map<String, Object> page) {
        return baseMapper.listAll(page);
    } */

    @Override
    public JSONObject list(PageResult2<T> page, BillFee billFee, User loginUser)  throws Exception{
        return billFeeBiz.list(page,billFee,loginUser);
    }

    @Override
    public List<BillFee> list(BillFee billFee, User loginUser) {
        return billFeeBiz.list(billFee,loginUser);
    }

    @Override
    public BillFee getById(BillFee billFee) {
        return billFeeBiz.getById(billFee);
    }

    @Transactional
    @Override
    public JsonResult save(BillFee billFee, User loginUser) {
        if(Utils.isEmpty(billFee.getBillId())){
            return JsonResult.error("请填写订单id,操作失败!");
        }
        if (billFeeBiz.save(billFee, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult saveBatch(List<BillFee> billFeeList, User loginUser) {
        for (BillFee billFee: billFeeList) {
            if(Utils.isEmpty(billFee.getBillId())){
                return JsonResult.error("请填写订单id,操作失败!");
            }
            billFeeBiz.save(billFee, loginUser);
        }
        return JsonResult.ok("添加成功");
    }

    @Transactional
    @Override
    public JsonResult update(BillFee billFee, User loginUser) {
        if(Utils.isEmpty(billFee.getId())
        ){
            return JsonResult.error("请填写id,操作失败!");
        }
        if (billFeeBiz.update(billFee, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(BillFee billFee, User loginUser) {
        if(Utils.isEmpty(billFee.getId())
        ){
            return JsonResult.error("请填写id,操作失败!");
        }
        if (billFeeBiz.remove(billFee, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
